#include "NxModelServiceRecordFactory.h"
#include "NxModelServiceRecord.h"
#include "NxDataFactory.h"

NJGIS::SERVICE::INjModelServiceRecord* NJGIS::SERVICE::NjModelServiceRecordFactory::createModelServiceRecordByJSON( Json::Value &jMsr, const char* ip, int port )
{
	NJGIS::SERVICE::NjRecordStatus restatus;
	if(jMsr["msr_status"].asInt() == 1){
		restatus = NJGIS::SERVICE::NjRecordStatus::MSRS_FINISHED;
	}else if(jMsr["msr_status"].asInt() == 0){
		restatus = NJGIS::SERVICE::NjRecordStatus::MSRS_UNFINISHED;
	}else{
		restatus = NJGIS::SERVICE::NjRecordStatus::MSRS_ERROR;
	}
	NJGIS::SERVICE::INjDataConfiguration* pInput = NJGIS::SERVICE::NjDataFactory::createDataConfigByJSON(jMsr["msr_input"]);
	NJGIS::SERVICE::INjDataConfiguration* pOutput = NJGIS::SERVICE::NjDataFactory::createDataConfigByJSON(jMsr["msr_output"]);
	NJGIS::SERVICE::INjModelServiceRecord* pMsr = new NJGIS::SERVICE::NjModelServiceRecord(
		jMsr["_id"].asString().c_str(),
		jMsr["ms_id"].asString().c_str(),
		jMsr["msr_datetime"].asString().c_str(),
		jMsr["msr_span"].asDouble(),
		jMsr["msr_guid"].asCString(),
		pInput,
		pOutput,
		restatus,
		jMsr["msr_runninginfo"]["StdOut"].asString().c_str(),
		jMsr["msr_runninginfo"]["StdErr"].asString().c_str(),
		jMsr["msr_runninginfo"]["InvokeErr"].asString().c_str(),
		ip,
		port
		);
	return pMsr;
}